﻿//去除字符串头尾空格或指定字符  
String.prototype.Trim = function (c) {
	if (c == null || c == "") {
		var str = this.replace(/^s*/, '');
		var rg = /s/;
		var i = str.length;
		while (rg.test(str.charAt(--i)));
		return str.slice(0, i + 1);
	}
	else {
		var rg = new RegExp("^" + c + "*");
		var str = this.replace(rg, '');
		rg = new RegExp(c);
		var i = str.length;
		while (rg.test(str.charAt(--i)));
		return str.slice(0, i + 1);
	}
}
//去除字符串头部空格或指定字符  
String.prototype.TrimStart = function (c) {
	if (c == null || c == "") {
		var str = this.replace(/^s*/, '');
		return str;
	}
	else {
		var rg = new RegExp("^" + c + "*");
		var str = this.replace(rg, '');
		return str;
	}
}

//去除字符串尾部空格或指定字符  
String.prototype.TrimEnd = function (c) {
	if (c == null || c == "") {
		var str = this;
		var rg = /s/;
		var i = str.length;
		while (rg.test(str.charAt(--i)));
		return str.slice(0, i + 1);
	}
	else {
		var str = this;
		var i = str.length;
		var endChar = str.charAt(i - 1);
		var rg = new RegExp(c);
		if (endChar==c) {
			return str.slice(0, i - 1);
		}
		else {
			return str;
		}
	}
}
// 对Date的扩展，将 Date 转化为指定格式的String
// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符， 
// 年(y)可以用 1-4 个占位符，毫秒(S)只能用 1 个占位符(是 1-3 位的数字) 
// 例子： 
// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423 
// (new Date()).Format("yyyy-M-d h:m:s.S")      ==> 2006-7-2 8:9:4.18 
Date.prototype.Format = function (fmt) { 
	var o = {
		"M+": this.getMonth() + 1, //月份 
		"d+": this.getDate(), //日 
		"h+": this.getHours(), //小时 
		"m+": this.getMinutes(), //分 
		"s+": this.getSeconds(), //秒 
		"q+": Math.floor((this.getMonth() + 3) / 3), //季度 
		"S": this.getMilliseconds() //毫秒 
	};
	if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	for (var k in o)
		if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
	return fmt;
}
//把字符串转换成日期格式。示例：formatDateTime(strDate,"yyyy-MM-dd hh:mm:ss")
function formatDateTime(inputTime,fmt) {
	var date = new Date(inputTime);
	if (fmt == null || fmt == "")
		fmt = "yyyy-MM-dd hh:mm:ss";
	return date.Format(fmt);
}
/**
 * 显示日期字符串
 * @param {any} inputTime:日期
 * @param {any} fmt:日期格式(yyyy-MM-dd hh:mm:ss)
 */
function showDateTime(inputTime, fmt) {
	if (!inputTime) {
		return "";
	}
	var result = formatDateTime(inputTime, fmt);
	if (result == "9999-12-31 23:59:59") {
		return "";
	}
	return result;
}
//在指定对像中显示当前时间（格式：2006年07月02日 星期一）
function getHTMLDate(obj) {
	var d = new Date();
	var weekday = new Array(7);
	var _mm = "";
	var _dd = "";
	var _ww = "";
	weekday[0] = "星期日";
	weekday[1] = "星期一";
	weekday[2] = "星期二";
	weekday[3] = "星期三";
	weekday[4] = "星期四";
	weekday[5] = "星期五";
	weekday[6] = "星期六";
	_yy = d.getFullYear();
	_mm = d.getMonth() + 1;
	_dd = d.getDate();
	_ww = weekday[d.getDay()];
	obj.html(_yy + "年" + _mm + "月" + _dd + "日 " + _ww);
}

function GetID(id) {
	return document.getElementById(id);
}
/**
 * 通过ID得到jquery对像
 * @param {any} id
 */
function GetJQ(id) {
	var obj = GetID(id);
	return $(obj);
}

/* 过滤HTML符号 */
function RemoveHtml(instr) {
	var d = document.createElement("DIV");
	d.innerHTML = instr;
	d.id = "tempremovehtmlcontent";
	d.style.display = "none";
	return d.innerText;
}

//加入收藏
function AddFavorite(sURL, sTitle) {
	try {
		if (window.sidebar) // Firefox
		{
			window.sidebar.addPanel(sTitle, sURL, "");
		}
		else if (window.opera && window.print) // Opera
		{
			var elem = document.createElement('a');
			elem.setAttribute('href', sURL);
			elem.setAttribute('title', sTitle);
			elem.setAttribute('rel', 'sidebar'); // required to work in opera 7+
			elem.click();
		}
		else if (document.all) // IE
		{
			try {
				window.external.AddFavorite(sURL, sTitle);
			}
			catch (e) {
				window.external.addToFavoritesBar(sURL, sTitle);  //IE8
			}
		}
		else {
			alert("由于浏览器的限制，请使用Ctrl+D手动收藏！");
		}
	}
	catch (e) {
		alert("由于浏览器的限制，请使用Ctrl+D手动收藏！");
	}
}
//设为首页
function SetHome(vrl) {
	if (document.all) {
		document.body.style.behavior = 'url(#default#homepage)';
		document.body.setHomePage(vrl);
	} else if (window.sidebar) {
		if (window.netscape) {
			try {
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
			} catch (e) {
				alert("该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true");
			}
		}
		var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
		prefs.setCharPref('browser.startup.homepage', vrl);
	}
}

//得到随机数
function RandomNum(n) {
	var rnd = '';
	for (var i = 0; i < n; i++)
		rnd += Math.floor(Math.random() * 10);
	return rnd;
}

//刷新验证码
function RefreshValdisplayDateCodeImage(ValdisplayDateCodeImageControl) {
	ValdisplayDateCodeImageControl.src = ValdisplayDateCodeImageControl.src + '?code=' + RandomNum(10);
}

//生成新编号。格式：yyyyMMddHHmmssfff +４位随机数
function GetNewNumber() {
	return (new Date()).Format("yyyyMMddhhmmssS") + RandomNum(4);
}

//用于回车后产生按纽点击事件
//使用方式：onkeypress="javascript:return DefaultButton(event, 'BtnLogOnAjax')"
function DefaultButton(event, linkOpenType) {
	if (event.keyCode == 13 && !(event.srcElement && (event.srcElement.tagName.toLowerCase() == "textarea"))) {
		var defaultButton = GetID(linkOpenType);
		if (defaultButton && typeof (defaultButton.click) != "undefined") {
			defaultButton.click();
			event.cancelBubble = true;
			if (event.stopPropagation)
				event.stopPropagation();
			return false;
		}
	}
	return true;
}

//获取url中的参数
//name：参数名称；decodeType：参数值解码方式；
function getUrlParam(name, decodeType) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
	var r = window.location.search.substr(1).match(reg);  //匹配目标参数
	if (r != null) {
		switch (decodeType) {
			case 0:
				return unescape(r[2]);
			case 1:
				return decodeURI(r[2]);
			case 2:
				return decodeURIComponent(r[2]);
			default:
				return unescape(r[2]);
		}
	}
	return null;
}

//iframe自动适应页面高度
//IFrameIDs：用逗号分隔的iframe的ID
function dynIFrameSize(IFrameIDs) {
	var arrIFrameIDs = IFrameIDs.split(",");
	for (i = 0; i < arrIFrameIDs.length; i++) {
		if (document.getElementById) {
			var dyniframe = document.getElementById(arrIFrameIDs[i]);
			if (dyniframe && !window.opera) {
				dyniframe.style.display = "block";
				//如果用户的浏览器是NetScape
				if (dyniframe.contentDocument && dyniframe.contentDocument.body.offsetHeight) {
					if (dyniframe.contentDocument.body.offsetHeight <= 450) {
						dyniframe.style.height = 450 + "px";
					} else {
						dyniframe.style.height = (dyniframe.contentDocument.body.offsetHeight + 5) + "px";
					}
				}
				else if (dyniframe.Document && dyniframe.Document.body) //如果用户的浏览器是IE
				{
					if (dyniframe.Document.body.scrollHeight) {
						if (dyniframe.Document.body.scrollHeight <= 450) {
							dyniframe.style.height = 450;
						} else {
							dyniframe.style.height = dyniframe.Document.body.scrollHeight + 5;
						}
					}
				}
			}
		}
	}
}

/**
 * 绑定节点类别
 * @param {any} ParentID 父节点ID
 * @param {any} SelectCategory 被选中的节点ID
 * @param {any} ctlID 显示的控件ID
 */
function DataBindCategory(ParentID, SelectCategory, ctlID) {
	var $obj = GetJQ(ctlID);
	if ($obj.length == 0) {
		return;
	}
	var url = '/Common/IndustryCategory';
	$.ajax({
		type: "POST",
		url: url,
		data: { "ParentID": ParentID, "SelectCategory": SelectCategory },
		async: false,
		headers: {
			"X-CSRF-TOKEN-JXWebHost": $("input[name='AntiforgeryFieldname']").val()
		},
		error: function (data, status, e) {
			layer.alert('加载失败!');
		},
		success: function (returnData) {
			if (returnData.Status == "1") {
				$obj.empty();
				$obj.append(returnData.Data);
			}
			else {
				//layer.alert(returnData.Msg);
			}
		}
	});
}
function SelectCategory1(PrefixID) {
	DataBindCategory($("#" + PrefixID + "Category1").val(), "", PrefixID + "Category2");
	DataBindCategory($("#" + PrefixID + "Category2").val(), "", PrefixID + "Category3");
	DataBindCategory($("#" + PrefixID + "Category3").val(), "", PrefixID + "Category4");
	SaveCategory(PrefixID);
}
function SelectCategory2(PrefixID) {
	DataBindCategory($("#" + PrefixID + "Category2").val(), "", PrefixID + "Category3");
	DataBindCategory($("#" + PrefixID + "Category3").val(), "", PrefixID + "Category4");
	SaveCategory(PrefixID);
}
function SelectCategory3(PrefixID) {
	DataBindCategory($("#" + PrefixID + "Category3").val(), "", PrefixID + "Category4");
	SaveCategory(PrefixID);
}
function SelectCategory4(PrefixID) {
	SaveCategory(PrefixID);
}
function InitCategory(SelectCategory, RootID, PrefixID) {
	if (!RootID || RootID == "") {
		RootID = -1;
	}
	var Category1 = -1;
	var Category2 = -1;
	var Category3 = -1;
	var Category4 = -1;
	var arrList = SelectCategory.split(',');
	if (arrList.length == 4) {
		Category1 = arrList[0];
		Category2 = arrList[1];
		Category3 = arrList[2];
		Category4 = arrList[3];
	}
	DataBindCategory(RootID, Category1, PrefixID + "Category1");
	DataBindCategory(Category1, Category2, PrefixID + "Category2");
	DataBindCategory(Category2, Category3, PrefixID + "Category3");
	DataBindCategory(Category3, Category4, PrefixID + "Category4");
}
function SaveCategory(PrefixID) {
	var Category1 = $("#" + PrefixID + "Category1").val();
	var Category2 = $("#" + PrefixID + "Category2").val();
	var Category3 = $("#" + PrefixID + "Category3").val();
	var Category4 = $("#" + PrefixID + "Category4").val();
	var data = "";
	if (Category1 != "") {
		data = Category1 + "," + Category2 + "," + Category3 + "," + Category4;
	}
	GetJQ(PrefixID).val(data);
}

/**
 * 绑定国家
 * @param {any} country 选中的国家
 * @param {any} PrefixID 被绑定控件ID的前缀
 */
function DataBindCountry(country, PrefixID) {
	var objID = PrefixID + "Country";
	var $obj = GetJQ(objID);
	if ($obj.length == 0) {
		return;
	}
	var Action = "Country";
	var url = '/Common/Region';
	$.ajax({
		type: "POST",
		url: url,
		data: { "Action": Action, "Country": country },
		async: false,
		headers: {
			"X-CSRF-TOKEN-JXWebHost": $("input[name='AntiforgeryFieldname']").val()
		},
		error: function (data, status, e) {
			layer.alert('加载失败!');
		},
		success: function (returnData) {
			if (returnData.Status == "1") {
				$obj.empty();
				$obj.append(returnData.Data);
			}
			else {
				//layer.alert(returnData.Msg);
			}
		}
	});
}
/**
 * 绑定省份
 * @param {any} country 所属的国家
 * @param {any} province 选中的省份
 * @param {any} PrefixID 被绑定控件ID的前缀
 */
function DataBindProvince(country, province, PrefixID) {
	var objID = PrefixID + "Province";
	var $obj = GetJQ(objID);
	if ($obj.length == 0) {
		return;
	}
	var Action = "Province";
	var url = '/Common/Region';
	$.ajax({
		type: "POST",
		url: url,
		data: { "Action": Action, "Country": country, "Province": province },
		async: false,
		headers: {
			"X-CSRF-TOKEN-JXWebHost": $("input[name='AntiforgeryFieldname']").val()
		},
		error: function (data, status, e) {
			layer.alert('加载失败!');
		},
		success: function (returnData) {
			if (returnData.Status == "1") {
				$obj.empty();
				$obj.append(returnData.Data);
			}
			else {
				//layer.alert(returnData.Msg);
			}
		}
	});
}
/**
 * 绑定城市
 * @param {any} province 所属的省份
 * @param {any} city 选中的城市
 * @param {any} PrefixID 被绑定控件ID的前缀
 */
function DataBindCity(province, city, PrefixID) {
	var objID = PrefixID + "City";
	var $obj = GetJQ(objID);
	if ($obj.length == 0) {
		return;
	}
	var Action = "City";
	var url = '/Common/Region';
	$.ajax({
		type: "POST",
		url: url,
		data: { "Action": Action, "Province": province, "City": city },
		async: false,
		headers: {
			"X-CSRF-TOKEN-JXWebHost": $("input[name='AntiforgeryFieldname']").val()
		},
		error: function (data, status, e) {
			layer.alert('加载失败!');
		},
		success: function (returnData) {
			if (returnData.Status == "1") {
				$obj.empty();
				$obj.append(returnData.Data);
			}
			else {
				//layer.alert(returnData.Msg);
			}
		}
	});
}
/**
 * 绑定区县
 * @param {any} city 所属的城市
 * @param {any} area 选中的区县
 * @param {any} PrefixID 被绑定控件ID的前缀
 */
function DataBindArea(city, area, PrefixID) {
	var objID = PrefixID + "Area";
	var $obj = GetJQ(objID);
	if ($obj.length == 0) {
		return;
	}
	var Action = "Area";
	var url = '/Common/Region';
	$.ajax({
		type: "POST",
		url: url,
		data: { "Action": Action, "City": city, "Area": area },
		async: false,
		headers: {
			"X-CSRF-TOKEN-JXWebHost": $("input[name='AntiforgeryFieldname']").val()
		},
		error: function (data, status, e) {
			layer.alert('加载失败!');
		},
		success: function (returnData) {
			if (returnData.Status == "1") {
				$obj.empty();
				$obj.append(returnData.Data);
			}
			else {
				//layer.alert(returnData.Msg);
			}
		}
	});
}
/**
 * 绑定街道
 * @param {any} area 所属的区县
 * @param {any} area1 选中的街道
 * @param {any} PrefixID 被绑定控件ID的前缀
 */
function DataBindArea1(area, area1, PrefixID) {
	var objID = PrefixID + "Area1";
	var $obj = GetJQ(objID);
	if ($obj.length == 0) {
		return;
	}
	var Action = "Area1";
	var url = '/Common/Region';
	$.ajax({
		type: "POST",
		url: url,
		data: { "Action": Action, "Area": area, "Area1": area1 },
		async: false,
		headers: {
			"X-CSRF-TOKEN-JXWebHost": $("input[name='AntiforgeryFieldname']").val()
		},
		error: function (data, status, e) {
			layer.alert('加载失败!');
		},
		success: function (returnData) {
			if (returnData.Status == "1") {
				$obj.empty();
				$obj.append(returnData.Data);
			}
			else {
				//layer.alert(returnData.Msg);
			}
		}
	});
}
/**
 * 绑定小区
 * @param {any} area1 所属的街道
 * @param {any} area2 选中的小区
 * @param {any} PrefixID 被绑定控件ID的前缀
 */
function DataBindArea2(area1, area2, PrefixID) {
	var objID = PrefixID + "Area2";
	var $obj = GetJQ(objID);
	if ($obj.length == 0) {
		return;
	}
	var Action = "Area2";
	var url = '/Common/Region';
	$.ajax({
		type: "POST",
		url: url,
		data: { "Action": Action, "Area1": area1, "Area2": area2 },
		async: false,
		headers: {
			"X-CSRF-TOKEN-JXWebHost": $("input[name='AntiforgeryFieldname']").val()
		},
		error: function (data, status, e) {
			layer.alert('加载失败!');
		},
		success: function (returnData) {
			if (returnData.Status == "1") {
				$obj.empty();
				$obj.append(returnData.Data);
			}
			else {
				//layer.alert(returnData.Msg);
			}
		}
	});
}
function SelectCountry(PrefixID) {
	DataBindProvince(GetJQ(PrefixID + "Country").val(), "", PrefixID);
	DataBindCity(GetJQ(PrefixID + "Province").val(), "", PrefixID);
	DataBindArea(GetJQ(PrefixID + "City").val(), "", PrefixID);
	DataBindArea1(GetJQ(PrefixID + "Area").val(), "", PrefixID);
	DataBindArea2(GetJQ(PrefixID + "Area1").val(), "", PrefixID);
}
function SelectProvince(PrefixID) {
	DataBindCity(GetJQ(PrefixID + "Province").val(), "", PrefixID);
	DataBindArea(GetJQ(PrefixID + "City").val(), "", PrefixID);
	DataBindArea1(GetJQ(PrefixID + "Area").val(), "", PrefixID);
	DataBindArea2(GetJQ(PrefixID + "Area1").val(), "", PrefixID);
}
function SelectCity(PrefixID) {
	DataBindArea(GetJQ(PrefixID + "City").val(), "", PrefixID);
	DataBindArea1(GetJQ(PrefixID + "Area").val(), "", PrefixID);
	DataBindArea2(GetJQ(PrefixID + "Area1").val(), "", PrefixID);
}
function SelectArea(PrefixID) {
	DataBindArea1(GetJQ(PrefixID + "Area").val(), "", PrefixID);
	DataBindArea2(GetJQ(PrefixID + "Area1").val(), "", PrefixID);
}
function SelectArea1(PrefixID) {
	DataBindArea2(GetJQ(PrefixID + "Area1").val(), "", PrefixID);
}
/**
 * 初始化区域控件
 * @param {any} country：选中的国家；
 * @param {any} province：选中的省份；
 * @param {any} city：选中的城市；
 * @param {any} area：选中的区县；
 * @param {any} PrefixID：被绑定控件ID的前缀；
 */
function InitRegion(country, province, city, area, PrefixID) {
	if (country == null || country == "")
		country = "中华人民共和国";
	DataBindCountry(country, PrefixID);
	DataBindProvince(country, province, PrefixID);
	DataBindCity(province, city, PrefixID);
	DataBindArea(city, area, PrefixID);
}
/**
 * 初始化区域控件
 * @param {any} country 选中的国家
 * @param {any} province 选中的省份
 * @param {any} city 选中的城市
 * @param {any} area 选中的区县
 * @param {any} area1 选中的街道
 * @param {any} area2 选中的小区
 * @param {any} PrefixID 被绑定控件ID的前缀
 */
function InitRegionFive(country, province, city, area, area1, area2, PrefixID) {
	if (country == null || country == "")
		country = "中华人民共和国";
	DataBindCountry(country, PrefixID);
	DataBindProvince(country, province, PrefixID);
	DataBindCity(province, city, PrefixID);
	DataBindArea(city, area, PrefixID);
	DataBindArea1(area, area1, PrefixID);
	DataBindArea2(area1, area2, PrefixID);
}

function IsWeiXin() {
	var ua = navigator.userAgent.toLowerCase();
	if (ua.match(/MicroMessenger/i) == "micromessenger") {
		return true;
	} else {
		return false;
	}
}
function ShowWeiXinTip() {
	var isWeixin = IsWeiXin();
	if (isWeixin) {
		var winHeight = typeof window.innerHeight != 'undefined' ? window.innerHeight : document.documentElement.clientHeight;
		var weixinTip = $('<div id="weixinTip"><p><img src="/Images/live_weixin.png" alt="微信打开" width="100%" /></p></div>');
		$("body").append(weixinTip);
		$("#weixinTip").css({
			"position": "fixed",
			"left": "0",
			"top": "0",
			"height": winHeight,
			"width": "100%",
			"z-index": "1000",
			"background-color": "rgba(0,0,0,0.8)",
			"filter": "alpha(opacity=80)",
		});
		$("#weixinTip p").css({
			"text-align": "center",
			"margin-top": "10%",
			"padding-left": "5%",
			"padding-right": "5%"
		});
	}
}

/*弹出层*/
/*
	参数解释：
	title	标题
	url		请求的url
	w		弹出层宽度（缺省调默认值）
*/
function layer_show(title, url, w='800') {
	if (title == null || title == '') {
		title = false;
	};
	if (url == null || url == '') {
		url = "404.html";
	};
	if (w == null || w == '') {
		w = 'auto';
	}
	else {
		var w1 = $(window).width();
		if (w > w1) {
			w = w1;
		}
		w = w + 'px';
	}
	var h = ($(window).height() - 50) + 'px';
	layer.open({
		type: 2,
		area: [w,h],
		fix: false, //不固定
		maxmin: true,
		shade: 0.4,
		title: title,
		content: url
		, btn: ['关闭']
	});
}
//全屏弹出层
function layer_showFull(title, url) {
	if (title == null || title == '') {
		title = false;
	};
	if (url == null || url == '') {
		url = "404.html";
	};
	var index = layer.open({
		type: 2,
		area: 'auto',
		fix: false, //不固定
		maxmin: true,
		shade: 0.4,
		title: title,
		content: url
		, btn: ['关闭']
	});
	layer.full(index);
}
/*关闭弹出框口*/
function layer_close() {
	var index = parent.layer.getFrameIndex(window.name);
	parent.layer.close(index);
}
/*
 * 关闭弹出层并刷新父页面
 */
function layer_closeRefresh() {
	var index = parent.layer.getFrameIndex(window.name);
	parent.layer.close(index);
	parent.location.reload();
}
//从子窗口刷新父页面
function RefreshParent() {
	parent.location.reload();
}
/*
 *加载层，示例：var index = loading(); 关闭：layer.close(index);
 */
function loading() {
	var index = layer.load(0, {
		time: 30 * 1000
	});
	return index;
}

/**
 * 在指定文本控件中追加新的内容
 * @param {any} addText：追加的内容；
 * @param {any} clientID：文本控件的ID；
 * @param {any} split：分隔符，默认为“,”
 */
function AppendStringToControl(addText, clientID, split=",") {
	var ctlValue = GetID(clientID).value;
	if (ctlValue == "") {
		GetID(clientID).value = addText;
	}
	else {
		var s = ctlValue.split(split);
		for (j = 0; j < s.length; j++) {
			if (s[j] == addText)
				return;
		}
		if (ctlValue.substr(ctlValue.length - 1, 1) == split) {
			GetID(clientID).value += addText;
		}
		else {
			GetID(clientID).value += split + addText;
		}
	}
	GetID(clientID).focus();
}

//通过腾讯发送验证码
var valSendCodeSMSID = "TencentCaptcha";
var valMobileID = "txtMobile";
var valImgCodeID = "txtImgCode";
var valCodeSMSTimer = parseInt(0);
function valCodeSMSCountdown() {
	if (valCodeSMSTimer == 0) {
		jQuery("#" + valSendCodeSMSID).html("获取验证码");
		jQuery("#" + valSendCodeSMSID).val("获取验证码");
		jQuery("#" + valSendCodeSMSID).removeAttr("disabled");
	} else {
		valCodeSMSTimer--;
		jQuery("#" + valSendCodeSMSID).html(valCodeSMSTimer + "秒后重发");
		jQuery("#" + valSendCodeSMSID).val(valCodeSMSTimer + "秒后重发");
		setTimeout("valCodeSMSCountdown()", 1000);
	}
}
function valCodeSMSSendCodeSMS(res) {
	// res（用户主动关闭验证码）= {ret: 2, ticket: null}
	// res（验证成功） = {ret: 0, ticket: "String", randstr: "String"}
	if (res.ret === 0) {
		if (valCodeSMSTimer != 0) {
			return false;
		}
		var mobile = jQuery("#" + valMobileID).val();
		if (mobile == null || mobile == '') {
			layer.alert('手机号码不能为空!');
			return false;
		}
		var ticket = res.ticket;
		var randstr = res.randstr;
		var url = '/Common/SendCodeSMS';
		$.ajax({
			type: "POST",
			url: url,
			data: { "mobile": mobile, "ticket": ticket, "randstr": randstr },
			headers: {
				"X-CSRF-TOKEN-JXWebHost": $("input[name='AntiforgeryFieldname']").val()
			},
			error: function (data, status, e) {
				layer.alert('网络超时，发送失败!');
			},
			success: function (returnData) {
				if (returnData.Status == "1") {
					valCodeSMSTimer = parseInt(90);
					$("#" + valSendCodeSMSID).html(valCodeSMSTimer + "秒后重发");
					$("#" + valSendCodeSMSID).val(valCodeSMSTimer + "秒后重发");
					$("#" + valSendCodeSMSID).attr({ "disabled": "disabled" });
					valCodeSMSCountdown();
				}
				else {
					layer.alert(returnData.Msg);
				}
			}
		});
	}
	else {
		layer.alert("验证失败");
		return false;
	}
}

//发送邮件
//mailToAddressID：收件人地址控件ID；subjectID：邮件标题控件ID；mailBodyID：邮件内容控件ID；
function SendMail(mailToAddressID, subjectID, mailBodyID) {
	var mailToAddress = jQuery("#" + mailToAddressID).val();
	if (mailToAddress == null || mailToAddress == '') {
		layer.alert('收件人邮箱不能为空!');
		return false;
	}
	var subject = jQuery("#" + subjectID).val();
	if (subject == null || subject == '') {
		layer.alert('邮件标题不能为空!');
		return false;
	}
	var mailBody = jQuery("#" + mailBodyID).val();
	if (mailBody == null || mailBody == '') {
		layer.alert('邮件内容不能为空!');
		return false;
	}
	var index = loading();
	var url = '/Common/SendMail';
	$.ajax({
		type: "POST",
		url: url,
		data: { "mailToAddress": mailToAddress, "subject": subject, "mailBody": mailBody },
		headers: {
			"X-CSRF-TOKEN-JXWebHost": $("input[name='AntiforgeryFieldname']").val()
		},
		error: function (data, status, e) {
			layer.close(index);
			layer.alert('服务器错误，发送失败!');
			return false;
		},
		success: function (returnData) {
			layer.close(index);
			if (returnData.Status == "1") {
				layer.alert(returnData.Msg);
			}
			else {
				layer.alert(returnData.Msg);
			}
		}
	});
}

//得到枚举类型的说明
function GetEnumDesc(enumType, enumValue) {
	var url = '/Common/GetEnumDescription';
	$.ajax({
		type: "POST",
		async: false,
		url: url,
		data: { "enumType": enumType, "enumValue": enumValue },
		headers: {
			"X-CSRF-TOKEN-JXWebHost": $("input[name='AntiforgeryFieldname']").val()
		},
		error: function (data, status, e) {
			return "";
		},
		success: function (returnData) {
			return returnData;
		}
	});
}
function GetUserTypeText(enumValue) {
	var result = "";
	switch (enumValue)
	{
		case 0:
			result = "个人会员";
			break;
		case 1:
			result = "商户-创建者";
			break;
		case 2:
			result = "商户-管理员";
			break;
		case 3:
			result = "商户成员";
			break;
		case 4:
			result = "商户-待审核成员";
			break;
		case 5:
			result = "商户成员";
			break;
		case 6:
			result = "商户成员";
			break;
		case 7:
			result = "商户成员";
			break;
	}
	return result;
}
function GetUserStatusText(enumValue) {
	var result = "";
	switch (enumValue) {
		case 0:
			result = "正常";
			break;
		case 1:
			result = "锁定";
			break;
		case 2:
			result = "等待邮件认证";
			break;
		case 4:
			result = "等待管理员认证";
			break;
		case 8:
			result = "等待手机短信认证";
			break;
		case 16:
			result = "不存在";
			break;
	}
	return result;
}
function GetUserMoneyTypeText(enumValue) {
	var moneyType = ["", "现金", "银行汇款", "在线支付", "余额", "分销提成", "佣金结算", "提现", "赠送", "补偿", "测试", "转移"];
	var result = moneyType[enumValue];
	return result;
}
function GetUserMoneyStatusHtml(userMoneyStatus) {
	if (parseInt(userMoneyStatus) == 1) {
		return "√";
	} else {
		return "<font color=red>×</font>";
	}
}
function GetUserMoneyHtml(userMoney) {
	if (parseFloat(userMoney) >= 1) {
		return ("<span style='color:red'>+" + userMoney + "</span>");
	} else if (parseFloat(userMoney) < 0){
		return "<span style='color:green'>" + userMoney + "</span>";
	} else {
		return userMoney;
	}
}
function GetUserExpHtml(userExp, IncomePayout) {
	if (parseInt(IncomePayout) == 1) {
		return ("<span style='color:red'>+" + userExp + "</span>");
	} else if (parseInt(IncomePayout) == 2) {
		return "<span style='color:green'>-" + userExp + "</span>";
	} else {
		return userExp;
	}
}
function GetUserPointHtml(userPoint, IncomePayout) {
	if (parseInt(IncomePayout) == 1) {
		return ("<span style='color:red'>+" + userPoint + "</span>");
	} else if (parseInt(IncomePayout) == 2) {
		return "<span style='color:green'>-" + userPoint + "</span>";
	} else {
		return userPoint;
	}
}
function GetUserValidHtml(userValid, IncomePayout) {
	if (parseInt(IncomePayout) == 1) {
		return ("<span style='color:red'>+" + userValid + "</span>");
	} else if (parseInt(IncomePayout) == 2) {
		return "<span style='color:green'>-" + userValid + "</span>";
	} else {
		return userValid;
	}
}
function GetValidNumHtml(validNumTime) {
	var days = -1;
	if (!validNumTime) {
		days = -1;
	} else {
		var endDate = Date.parse(validNumTime);
		var startDate = new Date().getTime();
		days = Math.ceil((endDate - startDate) / (1 * 24 * 60 * 60 * 1000));//上进 Math.ceil(12.1) = 13;
	}
	if (days < 0) {
		days = -1;
	}
	if (days >= 1) {
		return ("<span style='color:blue'>" + days + "</span>");
	} else {
		return "<span style='color:red'>" + days + "</span>";
	}
}
function GetPayOnlineStatusText(enumValue) {
	var enumType = ["", "未提交", "已提交", "已成功", "已失败"];
	var result = enumType[enumValue];
	return result;
}

/**
 * 初始化select2控件
 * @param {any} selectID：显示控件的ID；
 * @param {any} data：数据源，JSON数组格式[{id:0,text:'aaa'},{id:1,text:'bbb'}]
 * @param {any} selectValue：选中的值；
 * @param {any} isMultiple：控件是否能多选；
 */
function initSelect2(selectID, data, selectValue, isMultiple) {
	var placeholder = "请选择";
	if (isMultiple) {
		placeholder += "(可以多选)";
	}
	$("#" + selectID).select2({ language: "zh-CN", placeholder: placeholder,data:data, allowClear: true, multiple: isMultiple });
	$("#" + selectID).val(selectValue.split(',')).trigger("change");
}

/**
 * 初始化EditableSelect控件
 * @param {any} selectID：显示控件的ID；
 * @param {any} selectValue：选中的值；
 */
function initEditableSelect(selectID, selectValue="") {
	$('#' + selectID).editableSelect({
		filter: false,
		effects: 'fade',
		duration: 'fast'
	});
	$("#" + selectID).attr("value", selectValue);
}
/**
 * 展示商品属性类型的选中字段值
 * @param {any} ctlShowID：展示容器的ID；
 * @param {any} dataSourceID：数据源控件的ID；
 */
function ShowPropertySelect(ctlShowID, dataSourceID) {
	var selectValue = jQuery("#" + dataSourceID).val();
	var arrValue = selectValue.split("|");
	var html = "";
	for (i = 0; i < arrValue.length; i++) {
		if (arrValue[i].length > 0) {
			html += "<tr>";
			html += "<td>" + arrValue[i] + "</td>";
			html += "<td><button class=\"layui-btn layui-btn-xs layui-btn-danger\" type=\"button\" onclick=\"DelPropertyItem('" + arrValue[i] + "','" + ctlShowID + "','" + dataSourceID+"')\"><i class=\"layui-icon layui-icon-delete\"></i>删除</button></td>";
			html += "</tr>";
		}
	}
	$("#" + ctlShowID).empty();
	$("#" + ctlShowID).append(html);
}
/**
 * 添加商品属性类型的字段值到容器控件中
 * @param {any} item：字段值；
 * @param {any} ctlShowID：展示容器的ID；
 * @param {any} dataSourceID：数据源控件的ID；
 */
function AddPropertyItem(item, ctlShowID, dataSourceID) {
	if (!item || item == "") return;
	var selectValue = jQuery("#" + dataSourceID).val();
	if (!IsExistItem(item, selectValue,"|")) {
		if (selectValue.length > 0) {
			selectValue = selectValue + "|" + item;
		}
		else {
			selectValue = item;
		}
		jQuery("#" + dataSourceID).val(selectValue);
		ShowPropertySelect(ctlShowID, dataSourceID);
	}
}
/**
 * 删除商品属性类型的字段值从容器控件中
 * @param {any} item：字段值；
 * @param {any} ctlShowID：展示容器的ID；
 * @param {any} dataSourceID：数据源控件的ID；
 */
function DelPropertyItem(item, ctlShowID, dataSourceID) {
	if (item.length > 0) {
		var selectValue = jQuery("#" + dataSourceID).val();
		var arrValue = selectValue.split("|");
		var listItem = "";
		for (i = 0; i < arrValue.length; i++) {
			if (arrValue[i].length > 0) {
				if (arrValue[i] != item) {
					listItem += arrValue[i] + "|";
				}
			}
		}
		listItem = listItem.TrimEnd("|");
		jQuery("#" + dataSourceID).val(listItem);
		ShowPropertySelect(ctlShowID, dataSourceID);
	}
}

/**
 * 展示商品属性类型的选中字段值
 * @param {any} ctlShowID：展示容器的ID；
 * @param {any} dataSourceID：数据源控件的ID；
 */
function ShowProductStyleSelect(ctlShowID, dataSourceID) {
	var selectValue = jQuery("#" + dataSourceID).val();
	var arrValue = selectValue.split("|");
	$("#" + ctlShowID).empty();
	for (i = 0; i < arrValue.length; i++) {
		if (arrValue[i].length > 0) {
			var arrItem = arrValue[i].split("$");
			var uploadID = dataSourceID + "Upload" + i;
			var imgID = dataSourceID + "Img" + i;
			var hidTextID = dataSourceID + "HidText" + i;
			var hidUrlID = dataSourceID + "HidUrl" + i;
			var imgUrl = "";
			if (arrItem[1].length > 0) {
				imgUrl = "/UploadFiles/" + arrItem[1];
			}
			var html = "";
			html += "<tr>";
			html += "<td>" + arrItem[0] + "<input type=\"hidden\" id=\"" + hidTextID + "\" value=\"" + arrItem[0] +"\" /></td>";
			html += "<td>";
			html += "<button type=\"button\" class=\"layui-btn\" id=\"" + uploadID +"\"><i class=\"layui-icon\">&#xe67c;</i>上传图片</button>";
			html += "<div class=\"layui-upload-list\"><img class=\"layui-upload-img\" id=\"" + imgID + "\" src=\"" + imgUrl+"\" /></div>";
			html += "<input type=\"hidden\" id=\"" + hidUrlID + "\" value=\"" + arrItem[1] +"\" />";
			html += "</td>";
			html += "<td><button class=\"layui-btn layui-btn-xs layui-btn-danger\" type=\"button\" onclick=\"DelProductStyleItem('" + arrValue[i] + "','" + ctlShowID + "','" + dataSourceID + "')\"><i class=\"layui-icon layui-icon-delete\"></i>删除</button></td>";
			html += "</tr>";
			$("#" + ctlShowID).append(html);
			UploadProductStyleRender(uploadID, imgID, hidUrlID, ctlShowID,dataSourceID);
		}
	}
}
/**
 * 动态加载一个上传图片的控件
 * @param {any} uploadID 上传按纽ID
 * @param {any} showImg 显示图片的ID
 * @param {any} saveUrlID 保存上传路径的控件ID
 * @param {any} ctlShowID 展示容器的ID
 * @param {any} dataSourceID 数据源控件的ID
 */
function UploadProductStyleRender(uploadID, showImg, saveUrlID, ctlShowID,dataSourceID) {
	layui.use('upload', function () {
		var upload = layui.upload;
		var uploadImg = upload.render({
			elem: "#" + uploadID
			, url: '/Common/UploadImageHandle'
			, data: {}
			, before: function (obj) {
			}
			, done: function (res) {
				if (res.Status == 1) {
					$("#" + showImg).attr('src', "/UploadFiles/" + res.Data);
					$("#" + saveUrlID).val(res.Data);
					ResetDataSource(ctlShowID, dataSourceID);
					return layer.msg('上传成功');
				}
				else {
					return layer.msg(res.Msg);
				}
			}
			, error: function () {
				return layer.msg('上传失败');
			}
		});
	});
}
/**
 * 重置数据源控件的数据
 * @param {any} ctlShowID 展示容器的ID
 * @param {any} dataSourceID 数据源控件的ID
 */
function ResetDataSource(ctlShowID, dataSourceID) {
	var fileList = $("#" + ctlShowID);
	if (fileList) {
		var savaData = "";
		fileList.find("tr").each(function () {
			var tdArr = $(this).children();
			var textValue = tdArr.eq(0).find("input[type='hidden']").val();
			var imgSrc = tdArr.eq(1).find("input[type='hidden']").val();
			if (savaData == "") {
				savaData = textValue + "$" + imgSrc;
			}
			else {
				savaData = savaData + "|" + textValue + "$" + imgSrc;
			}
		});
		$("#" + dataSourceID).val(savaData);
	}
}
/**
 * 添加商品属性类型的字段值到容器控件中
 * @param {any} item：字段值；
 * @param {any} ctlShowID：展示容器的ID；
 * @param {any} dataSourceID：数据源控件的ID；
 */
function AddProductStyleItem(item, ctlShowID, dataSourceID) {
	if (!item || item == "") return;
	var arrAddItem = item.split("$");
	var selectValue = jQuery("#" + dataSourceID).val();
	var arrValue = selectValue.split("|");
	for (i = 0; i < arrValue.length; i++) {
		if (arrValue[i].length > 0) {
			var arrItem = arrValue[i].split("$");
			if (arrItem[0] == arrAddItem[0]) {
				return false;
			}
		}
	}
	if (selectValue.length > 0) {
		selectValue = selectValue + "|" + item;
	}
	else {
		selectValue = item;
	}
	jQuery("#" + dataSourceID).val(selectValue);
	ShowProductStyleSelect(ctlShowID, dataSourceID);
}
/**
 * 删除商品属性类型的字段值从容器控件中
 * @param {any} item：字段值；
 * @param {any} ctlShowID：展示容器的ID；
 * @param {any} dataSourceID：数据源控件的ID；
 */
function DelProductStyleItem(item, ctlShowID, dataSourceID) {
	if (item.length > 0) {
		var selectValue = jQuery("#" + dataSourceID).val();
		var arrDelItem = item.split("$");
		var arrValue = selectValue.split("|");
		var listItem = "";
		for (i = 0; i < arrValue.length; i++) {
			if (arrValue[i].length > 0) {
				var arrItem = arrValue[i].split("$");
				if (arrItem[0] != arrDelItem[0]) {
					listItem += arrValue[i] + "|";
				}
			}
		}
		listItem = listItem.TrimEnd("|");
		jQuery("#" + dataSourceID).val(listItem);
		ShowProductStyleSelect(ctlShowID, dataSourceID);
	}
}

/**
 * 检查是否存在
 * @param {any} checkItem：被检查值
 * @param {any} dataSource：数据源字符串
 * @param {any} separator：分隔符
 */
function IsExistItem(checkItem, dataSource, separator = ",") {
	if (checkItem.length <= 0 || dataSource.length <= 0) {
		return false;
	}
	var arrValue = dataSource.split(separator);
	for (i = 0; i < arrValue.length; i++) {
		if (arrValue[i] == checkItem) {
			return true;
		}
	}
	return false;
}
/**
 * 检查是否存在
 * @param {any} checkType：检查类型：Title,UserName
 * @param {any} checkValue：检查值
 */
function CheckIsExist(checkType, checkValue) {
	var url = '/Common/CheckIsExist';
	$.ajax({
		type: "POST",
		async: false,
		url: url,
		data: { "checkType": checkType, "checkValue": checkValue },
		headers: {
			"X-CSRF-TOKEN-JXWebHost": $("input[name='AntiforgeryFieldname']").val()
		},
		error: function (data, status, e) {
			return false;
		},
		success: function (returnData) {
			if (returnData.Status == 1) {
				return true;
			}
			else {
				return false;
			}
		}
	});
}
